module GrapeAPI
  module APIHelpers
    def data_compression(data)
      return ActiveSupport::Gzip.compress(data)
    end

    def has_user?(auth_token)
      User.getUserByAuthToken(auth_token)
    end
    
    def find_user?(login)
      User.where(["lower(username) = :value OR lower(email) = :value", { :value => _login.downcase }]).first
    end
    

    def signOutCurrentUser(user)
      sign_in(user)
    end

    def format_response
      @request_params = {}
      if (!request.env['request.params'].nil? && request.env['request.params'] != "")
        @request_params = JSON.parse(request.env['request.params'])
      end
      @request_params
    end
  end
end